﻿var province = $("#Provincial"), city = $("#Municipal");
var jobProvince = $("#JobProvincial"), jobCity = $("#JobMunicipal");
var bigPosition = $("#BigPosition"), smallPosition = $("#SmallPosition");
var bigIndustry = $("#BigIndustry"), smallIndustry = $("#SmallIndustry");
for (var i = 0; i < provinceList.length; i++) {  
    addEle(province, provinceList[i].name);   
}
for (var i = 0; i < provinceList.length; i++) {
    addEle(jobProvince, provinceList[i].name);
}
for (var i = 0; i < bigPositionList.length; i++) {
    addEle(bigPosition, bigPositionList[i].name);
}
for (var i = 0; i < bigIndustryList.length; i++) {
    addEle(bigIndustry, bigIndustryList[i].name);
}
init();
jobInit();
positionInit();
industryInit();
function init() {
    var provinceText111 = province.val();
    $.each(provinceList, function (i, item) {
        if (provinceText111 == item.name) {          
            $.each(provinceList[i].cityList, function (i, item) {
                addEle(city, item.name)
            });
            return i;
        }
    });
    
}
function jobInit() {
    var provinceText111 = jobProvince.val();
    $.each(provinceList, function (i, item) {
        if (provinceText111 == item.name) {
            $.each(provinceList[i].cityList, function (i, item) {
                addEle(jobCity, item.name)
            });
            return i;
        }
    });

}
function positionInit() {
    var positionText = bigPosition.val();
    $.each(bigPositionList, function (i, item) {
        if (positionText == item.name) {
            $.each(bigPositionList[i].smallPositionList, function (i, item) {
                addEle(smallPosition, item.name)
            });
            return i;
        }
    });

}
function industryInit() {
    var industryText = bigIndustry.val();
    $.each(bigIndustryList, function (i, item) {
        if (industryText == item.name) {
            $.each(bigIndustryList[i].smallIndustryList, function (i, item) {
                addEle(smallIndustry, item.name)
            });
            return i;
        }
    });

}
function addEle(ele,value){
    var optionStr="";
    optionStr = "<option value=" + value + ">" + value +"</option>";
    ele.append(optionStr);
}
function removeEle(ele){
    ele.find("option").remove();
    
}
var provinceText, cityText, jobProvinceText, jobCityText;
var bigPositionText, smallPositionText, bigIndustryText, smallIndustryText;
province.on("change",function(){
    provinceText=$(this).val();
    $.each(provinceList,function(i,item){
        if(provinceText == item.name){
            cityItem=i;
            return cityItem
        }
    });   
    removeEle(city);
    $.each(provinceList[cityItem].cityList, function (i, item) {
        addEle(city, item.name)
    });
});
jobProvince.on("change", function () {
    jobProvinceText = $(this).val();
    $.each(provinceList, function (i, item) {
        if (jobProvinceText == item.name) {
            cityItem = i;
            return cityItem
        }
    });
    removeEle(jobCity);
    $.each(provinceList[cityItem].cityList, function (i, item) {
        addEle(jobCity, item.name)
    });
});
bigPosition.on("change", function () {
    bigPositionText = $(this).val();
    $.each(bigPositionList, function (i, item) {
        if (bigPositionText == item.name) {
            cityItem = i;
            return cityItem
        }
    });
    removeEle(smallPosition);
    $.each(bigPositionList[cityItem].smallPositionList, function (i, item) {
        addEle(smallPosition, item.name)
    });
});
bigIndustry.on("change", function () {
    bigIndustryText = $(this).val();
    $.each(bigIndustryList, function (i, item) {
        if (bigIndustryText == item.name) {
            cityItem = i;
            return cityItem
        }
    });
    removeEle(smallIndustry);
    $.each(bigIndustryList[cityItem].smallIndustryList, function (i, item) {
        addEle(smallIndustry, item.name)
    });
});
//city.on("change",function(){
//    cityText=$(this).val();
//    removeEle(town);
//    $.each(provinceList,function(i,item){
//        if(provinceText == item.name){
//            cityItem=i;
//            return cityItem
//        }
//    });
//    $.each(provinceList[cityItem].cityList,function(i,item){
//        if(cityText == item.name){
//            for(var n=0;n<item.areaList.length;n++){
//                addEle(town,item.areaList[n])
//            }
//        }
//    });
//});